package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.*;

public class Library {

    private LinkedList<Book> books;
    private LinkedList<Movie> movies;
    private PrintStream ps;

    public Library() {
        this.ps = System.out;
        books = new LinkedList<Book>();
        movies = new LinkedList<Movie>();
    }

    public Library(PrintStream ps) {
        this.ps = ps;
        books = new LinkedList<Book>();
        movies = new LinkedList<Movie>();
    }

    public void addBook(String title) {
        books.add(new Book(title));
    }

    public void addMovie(String title, String year, String director, String rating) {
        movies.add(new Movie(title, year, director, rating));
    }

    public void reserveBook(String title) {
        Book b = search(title);
        if (b != null)
            ps.println("Thank You! Enjoy the book.");
        else
            ps.println("Sorry we don't have that book yet!");
    }

    public void printAllBooks() {
        for (Book book : books)
            ps.println(book.toString());
    }

    public void printAllMovies() {
        ps.println("Movie\t\tYear\tDirector\t\tRating");
        for (Movie movie : movies)
            ps.println(movie.toString());
    }


    public Book search(String title) {
        for (Book book : books)
            if (title.equals(book.toString()))
                return book;
        return null;
    }

    public LinkedList<Book> getBooks() {
        return books;
    }

    public LinkedList<Movie> getMovies() {
        return movies;
    }
}
